package com.maven.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.maven.bean.User;
import com.maven.service.UserService;

@RequestMapping("/loginController")
@Controller
public class loginController {

	@Autowired
	private UserService userService;
	
	@RequestMapping("/goLogin")
	public String gologin(){
		return "login";
	}
	
	@RequestMapping("/login")
	@ResponseBody
	public String login(HttpServletRequest request,User existUser){
		
		String username = request.getParameter("username");
		String pwd = request.getParameter("password");
		
	   existUser = userService.selectUserNameByPassword(username,pwd);
		
		if (existUser != null && existUser.getUsername().equals(username) && existUser.getPassword().equals(pwd)) {
		    return "login_succ";
		}else {
			return "login_fail";
		}
		
	}
}
